package com.itheimamobileguard.activitys;

import com.example.mobile.R;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.provider.Settings.System;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;



public class Setup2Activity extends BaseSetUpActivity{
	
	private TelephonyManager tm;
	private ImageView iv_setup2_status;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
		setContentView(R.layout.activity_setup2);
		iv_setup2_status = (ImageView) findViewById(R.id.iv_setup2_status);
		String saveSim = sp.getString("simNum", null);
		if(TextUtils.isEmpty(saveSim)){
			iv_setup2_status.setImageResource(R.drawable.ic_menu_close_clear_cancel);
		}else{
			iv_setup2_status.setImageResource(R.drawable.key);
		}
	}
	
	public void bindSim(View view){
		String saveSim = sp.getString("simNum", null);
		if(TextUtils.isEmpty(saveSim)){
			String sim = tm.getSimSerialNumber();
			Editor editor = sp.edit();
			editor.putString("simNum", sim);
			editor.commit();
			Toast.makeText(this, "绑定SIM卡成功", 0).show();
			iv_setup2_status.setImageResource(R.drawable.key);
		}else {
			Editor editor = sp.edit();
			editor.putString("simNum", null);
			editor.commit();
			Toast.makeText(this, "解绑SIM卡成功", 0).show();
			iv_setup2_status.setImageResource(R.drawable.ic_menu_close_clear_cancel);
		}

	}
	
	@Override
	public void showNext() {
		String saveSim = sp.getString("simNum", null);
		if(TextUtils.isEmpty(saveSim)){
			Toast.makeText(this, "请先绑定SIM卡", 0).show();
			return;
		}
		startAndFinshActivity(Setup3Activity.class);
	}

	@Override
	public void showPre() {
		startAndFinshActivity(Setup1Activity.class);		
	}
}
